import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';

import { Article, ArticleService } from './article.service';

@Component({
  templateUrl: './article-management.component.html',
  styleUrls: ['./article-management.component.less'],
})
export class ArticleManagementComponent implements OnInit {
  articles: Article[] = [];
  total: number = 0;
  query = { status: '0' };
  drawerVisible = false;
  currArticle: Article = null;

  constructor(private articleSrv: ArticleService, public router: Router) {}

  ngOnInit(): void {
    this.articleSrv.getArticles(1, 10).subscribe((res) => {
      this.articles = res.result;
      this.total = res.total;
    });
  }

  showDetailDrawer(article) {
    this.drawerVisible = true;
    this.currArticle = article;
  }

  closeDetailDrawer() {
    this.drawerVisible = false;
  }

  toDetail() {
    this.router.navigate([`articles/${this.currArticle._id}`]);
  }
}
